package com.jingdianjichi.wx.handler;

import com.jingdianjichi.wx.enums.WxMspTypeEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * WxTypeFactory 类
 *
 * @author 熊苏鹏1
 * @date 2025/3/3 21:17
 * @description
 */
@Component
public class WxTypeFactory implements InitializingBean {
    @Resource
    List<WxTypeHandler> handlers;
    Map<WxMspTypeEnum,WxTypeHandler> handlerMap = new HashMap<>();
    public WxTypeHandler getHandler(String type){
        return handlerMap.get(WxMspTypeEnum.getByType(type));

    }

    @Override
    public void afterPropertiesSet() throws Exception {
        handlers.forEach(handler -> handlerMap.put(handler.getType(),handler));

    }
}
